<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>霍安猜苹果小助手</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
    <style>
        body {
            background-color: #aaa;
        }

        .wrapper {
            max-width: 375px;
            background-color: #FFF;
            margin: 0 auto;
            padding: 10px 5px;
            position: relative;
        }

        .message-wrapper {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            text-align: center;
        }

        .message {
            position: absolute;
            width: 100%;
            box-sizing: border-box;
            opacity: 0;
            top: 0;
            transition: opacity .5s, top .5s;
            -webkit-transition: opacity .5s, top .5s;
        }

        .message span {
            display: inline-block;
            padding: 15px;
            color: #3c763d;
            border-radius: 4px;
            border: 1px solid #d6e9c6;
            background-color: #dff0d8;
            font-size: inherit;
        }

        .start-state .form-inline {
            display: flex;
            justify-content: space-between;
        }


        .start-state .form-inline .form-group {
            width: 120px;
            padding: 10px 0;
        }

        .start-state .form-group select {
            width: 100%;
        }
        .change-way button{
            text-align: end;
            padding: 15px 140px;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <div class="message-wrapper" id="message_wrapper">
        </div>
        <div class="title" style="text-align: center;">
            <h2>霍安猜苹果</h2>
        </div>
        <div class="start-state">
            <form class="form-inline">
                <div class="form-group">
                    <select class="form-control" id="first">
                        <option value="S" selected>S</option>
                        <option value="H">H</option>
                        <option value="A">A</option>
                    </select>
                </div>
                <div class="form-group">
                    <select class="form-control" id="second">
                        <option value="S">S</option>
                        <option value="H" selected>H</option>
                        <option value="A">A</option>
                    </select>
                </div>
                <div class="form-group">
                    <select class="form-control" id="third">
                        <option value="S">S</option>
                        <option value="H">H</option>
                        <option value="A" selected>A</option>
                    </select>
                </div>
            </form>
        </div>
        <div class="change-way" id="change-way">
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="33212311">33212311</button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="1232312" >1232312 </button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="3112313" >3112313 </button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="1223221" >1223221 </button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="12213231">12213231</button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="12213232">12213232</button>
            <button type="button" class="btn btn-default btn-lg btn-block" data-way="13312133">13312133</button>
        </div>
        <div class="rule">
            <h3 style="text-align: center;">说明</h3>
            <img src="rule.jpg" width="100%"/>
            <p>每次变化都是交换移动,所以只有3种移动,我们定义1就是左苹果和中苹果交换,2是右和中,3是左和右</p>
            <p>经过大佬总结,上面7个按钮的移动套路就是所有可能</p>
            <p>但是我们不需要观察整个套路的全部变换(比较难),一般可以选择记开头几个或者末尾几个</p>
            <p>这里推荐记末尾2次,因为记开头的话那三个122比较容易混乱,而末尾两次是比较有辨识度的</p>
        </div>
        <!-- 
            1232312
            12213232
            3112313
            1223221
            33212311
            12213231
            13312133
         -->
    </div>
</body>
<script>
    let map = {
        SHA: {
            '1232312': 'HSA',
            '12213232': 'HAS',
            '3112313': 'AHS',
            '1223221': 'SAH',
            '33212311': 'SHA',
            '12213231': 'SHA',
            '13312133': 'ASH'
        },
        SAH: {
            '1232312': 'AHS',
            '12213232': 'AHS',
            '3112313': 'HAS',
            '1223221': 'SHA',
            '33212311': 'SAH',
            '12213231': 'SAH',
            '13312133': 'HSA'
        },
        ASH: {
            '1232312': 'SAH',
            '12213232': 'SHA',
            '3112313': 'HSA',
            '1223221': 'AHS',
            '33212311': 'ASH',
            '12213231': 'ASH',
            '13312133': 'HAS'
        },
        AHS: {
            '1232312': 'HAS',
            '12213232': 'HSA',
            '3112313': 'SHA',
            '1223221': 'ASH',
            '33212311': 'AHS',
            '12213231': 'AHS',
            '13312133': 'SAH'
        },
        HAS: {
            '1232312': 'AHS',
            '12213232': 'ASH',
            '3112313': 'SAH',
            '1223221': 'HSA',
            '33212311': 'HAS',
            '12213231': 'HAS',
            '13312133': 'SHA'
        },
        HSA: {
            '1232312': 'SHA',
            '12213232': 'SAH',
            '3112313': 'ASH',
            '1223221': 'HAS',
            '33212311': 'HSA',
            '12213231': 'HSA',
            '13312133': 'AHS'
        },
    }
    console.log(JSON.stringify(map))
    document.getElementById('change-way').addEventListener('click', function (e) {
        if (e.target.tagName === 'BUTTON') {
            let key = document.getElementById('first').value + document.getElementById('second').value + document.getElementById('third').value
            if(!map[key]) alert('初始位置错误')
            let result = map[key][e.target.dataset.way]
            if (key !== result) {
                document.getElementById('first').value = result[0]
                document.getElementById('second').value = result[1]
                document.getElementById('third').value = result[2]
            }
            showMsg('位置变换成功' , 1000)
        }
    })
    let msg_arr = []
    function showMsg(str, microSec) {
        let message = document.createElement('div')
        message.className = 'message'
        for (let i = 0; i < msg_arr.length; i++) {
            msg_arr[i].style.top = (msg_arr[i].offsetTop + 65) + 'px'
        }
        msg_arr.push(message)
        message.innerHTML = '<span>' + str + '</span>'
        document.getElementById('message_wrapper').appendChild(message)
        message.style.top = '5px'
        message.style.opacity = '1'
        setTimeout(function () {
            for (let i = 0; i < msg_arr.length; i++) {
                if (message === msg_arr[i]) {
                    msg_arr.splice(i, 1)
                }
            }
            message.style.opacity = '0'
            setTimeout(function () {
                message.remove()
            }, 500)
        }, microSec)
    }
</script>

</html>